#!/bin/bash

RUN_LOG_FILENAME=./server/log/run.log
DATE_FORMAT="[%Y-%m-%d %H:%M:%S %z]"

function log_info() {
    echo $(date +"$DATE_FORMAT")"[INFO](updater):" $1 >> $RUN_LOG_FILENAME
}

./stop_server.sh

git stash

log_info "Stop for updating codes."

# Update codes
BRANCH_NAME="version"
git checkout -- .
git pull --rebase origin $BRANCH_NAME

git stash pop

log_info "Current version commit id: $(git rev-parse HEAD)"

./run_server.sh